package logger

import (
	"gitee.com/sunny-zhangqiang/zcache_new/comm"
	"os"
)

type Brush func(string) string

func NewBrush(color string) Brush {
	pre := "\033["
	reset := "\033[0m"
	return func(text string) string {
		return pre + color + "m" + text + reset
	}
}

var colors = []Brush{
	NewBrush("1;34"), // Debug    blue
	NewBrush("1;33"), // Warn     yellow
	NewBrush("1;31"), // Error    red
}

type StdOutput struct {
}

func (std *StdOutput) Output(level Level, s string) {
	os.Stdout.Write(comm.String2Bytes(colors[level](s)))
}

func (std *StdOutput) Flush() {
	// nothing
}

func (std *StdOutput) Close() {
	// nothing
}

func NewStdOutput() *StdOutput {
	return &StdOutput{}
}
